package com.group.eams.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.FlowLinkQueryDto;
import com.group.eams.pojo.entity.FlowLink;
import com.group.eams.service.FlowLinkService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 流程线表(FlowLink)表控制层
 *
 * @author DHUser
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/flowLink")
public class FlowLinkController  {
    /**
     * 服务对象
     */
    @Autowired
    private FlowLinkService flowLinkService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/find",method = RequestMethod.GET)
    public Result findById(@RequestParam Long id) {
        FlowLink flowLink = flowLinkService.getById(id);
        return Result.buildSuccess(flowLink);
    }

    /**
     * 分页查询
     *
     * @param flowLinkQueryDto 筛选条件
     * @return 查询结果
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result list(FlowLinkQueryDto flowLinkQueryDto) {
        Page<FlowLink> page = flowLinkService.findByQueryDto(flowLinkQueryDto);
        return Result.buildSuccess(page.getTotal(),page.getRecords());
    }

    /**
     * 查询所有数据
     * @return
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result findAll() {
        return Result.buildSuccess(flowLinkService.list());
    }

    /**
     * 新增数据
     *
     * @param flowLink 实例对象
     * @return 实例对象
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result add(@RequestBody FlowLink flowLink){
        boolean result = flowLinkService.save(flowLink);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 修改数据
     *
     * @param flowLink 实例对象
     * @return 实例对象
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result update(@RequestBody FlowLink flowLink){
        boolean result = flowLinkService.updateById(flowLink);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public Result deleteById(@RequestParam Long id) {
        boolean result = flowLinkService.removeById(id);
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量删除数据
     *
     * @param batchDeleteDto 主键
     * @return 是否成功
     */
    @RequestMapping(value = "/deleteBatch",method = RequestMethod.POST)
    public Result deleteBatch(@RequestBody BatchDeleteDto batchDeleteDto) {
        boolean result = flowLinkService.removeByIds(batchDeleteDto.getIds());
        return result ? Result.buildSuccess() : Result .buildFail(ResultEnum.OPTION_FAIL);
    }

}

